﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace 信息记录系统
{
    public partial class Form7 : Form
    {
        public Form7()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == string.Empty)
            {
                MessageBox.Show("实施商不能为空");
                return;
            }
            if (textBox2.Text == string.Empty)
            {
                MessageBox.Show("服务商不能为空");
                return;
            }
            if (textBox3.Text == string.Empty)
            {
                MessageBox.Show("IP地址或域名不能为空");
                return;
            }
            if (textBox4.Text == string.Empty)
            {
                MessageBox.Show("服务人员不能为空");
                return;
            }
            if (textBox5.Text == string.Empty)
            {
                MessageBox.Show("服务内容不能为空");
                return;
            }
            if (textBox6.Text == string.Empty)
            {
                MessageBox.Show("开始时间不能为空");
                return;
            }
            if (textBox7.Text == string.Empty)
            {
                MessageBox.Show("结束时间不能为空");
                return;
            }
            if (textBox8.Text == string.Empty)
            {
                MessageBox.Show("实施状态不能为空");
                return;
            }
            if (textBox9.Text == string.Empty)
            {
                MessageBox.Show("实施地区不能为空");
                return;
            }
            if (textBox10.Text == string.Empty)
            {
                MessageBox.Show("测试地点不能为空");
                return;
            }
            if (textBox11.Text == string.Empty)
            {
                MessageBox.Show("测试方式不能为空");
                return;
            }
            string connStr = "#";
            //创建 SqlConnection的实例
            MySqlConnection conn = null;
            try
            {
                conn = new MySqlConnection(connStr);
                //打开数据库连接
                conn.Open();
                //string sql = "insert into sys_user_data(customername,serviceaddress,systemversion,webversion,webname,webpath,webport,langues,sqltype,sqlpath,protect,nykeep,servicepurpose,serviesname,businessname,sqlport,servicestime,nowhy,uppertimes,clostimes,stautimes,notie,datapasswd) values('{0}','{1}')";
                string sql = "insert into sys_security_notie(Implementer,serviceimple,ipaddress,serviceuser,servienotie,stuatimes,clostimes,status,impleaddress,testaddress,testtypes,notie) values('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}')";
                //Implementer, ipaddress, serviceuser, servienotie, stuatimes, clostimes, status, impleaddress, testaddress, testtypes, notie, serviceimple
                //填充SQL语句
                // sql = string.Format(sql, textBox1.Text, textBox2.Text, textBox3.Text);
                sql = string.Format(sql, textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text, textBox5.Text, textBox6.Text, textBox7.Text, textBox8.Text, textBox9.Text, textBox10.Text, textBox11.Text, textBox12.Text);
                //创建SqlCommand对象
                MySqlCommand cmd = new MySqlCommand(sql, conn);
                //执行SQL语句
                int returnvalue = cmd.ExecuteNonQuery();
                //判断SQL语句是否执行成功
                if (returnvalue != -1)
                {
                    MessageBox.Show("数据添加成功！");
                    Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("数据添加失败！" + ex.Message);
            }
            finally
            {
                if (conn != null)
                {
                    //关闭数据库连接
                    conn.Close();
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            MessageBox.Show("功能未完善！！！");
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            Close();
        }

        private void button3_Click_1(object sender, EventArgs e)
        {
            MessageBox.Show("该功能未设计！");
        }
    }
}
